package com.deepexi.sample.controller;

import com.deepexi.sample.service.TreeService;
import com.deepexi.sample.vo.Result;
import com.deepexi.sample.vo.TreeVo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "树模块")
@RestController
public class MybatisController {

    //使用内置jackson
    @Autowired
    private ObjectMapper jacksonMapper;

    @Autowired
    private TreeService treeService;

    // @RequestMapping(value = "gettree")
    // public String GetTree() throws JsonProcessingException {
    //     List<TreeVo> list = treeService.GetTree();
    //     String jsonStr = jacksonMapper.writeValueAsString(list);
    //     return jsonStr;
    // }

    @ApiOperation(value = "获取目录树", notes = "获取目录树")
    @RequestMapping(value = "gettree")
    public Result GetTree() throws JsonProcessingException {
        List<TreeVo> list = treeService.GetTree();
        return Result.success(list);
    }
}
